var attendanceType;
var id;
var groupid;
var iconid;
var subid;
var menuid;
var businessId;
$(function(){
   	 groupid = ly.getUrlParam("groupid");
	 iconid = ly.getUrlParam("iconid");
	 subid = ly.getUrlParam("subid");
	 menuid = ly.getUrlParam("menuid");	

	attendanceType = ly.getUrlParam("attendanceType");
	id = ly.getUrlParam("id");
	if(attendanceType == 2){
		$(".body_title").html("编辑");
		  $(".form").getForm({ajaxform:true,
	        id: id
	   },function (data) {
			$("#isUsing").getSelect({
				type:"radio",
				asName:"isUsing",
				list:[
					{value:"1",display:"是"},
					{value:"0",display:"否"}
				],
				default:data.isUsing			
			});
			
			
	    });
	}else{
		$("#isUsing").getSelect({
			type:"radio",
			asName:"isUsing",
			list:[
				{value:"1",display:"启用"},
				{value:"0",display:"禁用"}
			],
			default:'1'			
		});
	}
	
	
	
	//提交
    $("body").on("click","#save-btn-commodityClassification",function(event){
        event.preventDefault();
        var success =  $('.form').validate('submitValidate');
        if(success){
			
            //验证通过提交表单
            submitFom();
        }
    })
	
	//批量删除
	$("#batchDelBtn").click(function(){
		var c = "";
		$("input[name=datachk]:checked").each(function(){
			c += $(this).val()+',';
		});
		deleteFirstCategory(c);
	});
});

/*
 * 提交表单
 */
function submitFom(){
    var workerName =$("#workerName").val();
 	var workerContext = $("#workerContext").val();
 	var workerCode = $("#workerCode").val();
 	var isUsing = $("#isUsing input:checked").val();
 	
  	var obj = {};
  	var url = site.apiUrl+"/back/worker/insertOrUpdateWorker";
  	if(attendanceType == 1){
		//新增
		 obj = {
	    	'workerName':workerName,
	    	'workerContext':workerContext,
	    	'workerCode':workerCode,
	    	'isUsing':isUsing
	    };
  	}else{
  		//修改
  		var thisId = $("#id").val();
  		obj = {
  			'workerName':workerName,
	    	'workerContext':workerContext,
	    	'isUsing':isUsing,
	    	'workerCode':workerCode,
  			'id':thisId
  		};
  	}
  	console.log(obj);
	request({
		url:url,
		data:obj,
		type:"post",
		callback:function(f) {
			console.log(f);
			if(f.code=="rest.success"){
				if(attendanceType == 1){
					ly.alert('保存成功',function(){	            
			    		ly.goto("worker-list.html");
			        });
				}else{
					ly.alert('修改成功',function(){	           
			    		ly.goto("worker-list.html");
			        });
				}
			}else{
				ly.toast(f.desc);
			}
		}
	});
  	
}
